[10.x] Fix Http::retry so that throw is respected for call signature Http::retry([1,2], throw: false) #52002
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Http::retry
accepts the first parameter for times as anarray|int
. The documentation states that:If all of the requests fail, an instance of
Illuminate\Http\Client\RequestException
will be thrown. If you would like to disable this behavior, you may provide a throw argument with a value of false.However an
Illuminate\Http\Client\RequestException
is thrown as can be seen by adding a test to HttpClientTest:Other tests have just been added to cover usage of the first parameter as an array.
This issue is due to PendingRequest.php:927 and PendingRequest.php:931 where the following comparisons are used:
even though
$this->tries
is an array. Suggested fix from this PR is to use:in place of
$this->tries
. Thecount($this->tries) + 1
is required as specifying the retries in an array already assumes that the first request has been made and that the backoff times specified will be used. Whereas specifying the number of tries assumes that it includes the first request.